//
//  TMTopViewManager.m
//  TMFishTravel
//
//  Created by Playboy on 2017/10/12.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "TMTopViewManager.h"
#import "TMTopView.h"
#import "TMNotificationView.h"

@interface TMTopViewManager ()

@property(nonatomic,strong)TMTopView *topView;
@property(nonatomic,strong)UIWindow *topWindow;
@property(nonatomic,strong)TMNotificationView *notiView;

@end


@implementation TMTopViewManager

-(UIWindow *)topWindow{
    if (_topWindow) {
        return _topWindow;
    }
    _topWindow=[[UIWindow alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 60)];
    _topWindow.windowLevel=1000;
    [_topWindow makeKeyAndVisible];
    return _topWindow;
}

+ (TMTopViewManager *)manger {
    static TMTopViewManager *sharedManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager = [[TMTopViewManager alloc]init];
    });
    return  sharedManager;
}

- (void)displayTopViewWithMessage:(NSString *)message {
    self.topView=[TMTopView viewWithMessage:message];
    [self.topWindow addSubview:self.topView];
    [self.topView showViewWithCompletion:^{
        [self cleanView];
    }];
}

- (void)notificationViewWithMessage:(NSString *)message completion:(void (^)(void))completion{
    self.notiView = [TMNotificationView viewWithMessage:message];
    [self.topWindow addSubview:self.notiView];
    [self.notiView showViewWithCompletion:^{
        if (completion) {
            completion();
        }
        [self cleanView];
    }];
}

-(void)cleanView{
    self.topView=nil;
    self.topWindow=nil;
    self.notiView=nil;
}

@end
